﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;

namespace HospitalMedicineTraceability
{
    /// <summary>
    /// ClassName:frmConfirmStockInCode
    /// Version:1.0
    /// Date:2024-06-26
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为实现扫码确定入库单号
    /// </remarks>    
    public partial class frmConfirmStockInCode : DevComponents.DotNetBar.OfficeForm
    {
        #region 01.自定义属性
        public string m_strSupplierCode = ""; // 配企编号
        public string m_strSupplierName = ""; // 配企名称
        public string m_strSupplierCode_Tax = ""; // 配企纳税人编码   
        public string m_strSupplierName_Tax = ""; // 配企纳税人名称
        public string m_strStockInCode = ""; // 入库单号
        #endregion
        public frmConfirmStockInCode()
        {
            InitializeComponent();
        }

        #region 02.自定义方法
        /// <summary>
        /// 取配送企业
        /// </summary>
        /// <param name="strCode"></param>
        public void _getSupplier(string strCode)
        {
            Form frm = new Form();
            try
            {
                string strSql = string.Format("exec P_GetStockInByCode '{0}'", strCode);
                DataTable dt = AppInfo._openSql_DataTable(strSql);
                string strResultKind = dt.Rows[0]["Result"].ToString();
                switch (strResultKind)
                {
                    case "1":
                        // 入库单据
                        txtSupplierCode.Text = string.Format("{1}|{0}", dt.Rows[0]["SupplierCode"].ToString(), dt.Rows[0]["SupplierName"].ToString());
                        txtStockInCode.Text = string.Format("{0}", dt.Rows[0]["StockInCode"].ToString());
                        break;
                    case "2":
                        // 发票
                        txtSupplierCode.Text = string.Format("{1}|{0}", dt.Rows[0]["SupplierCode"].ToString(), dt.Rows[0]["SupplierName"].ToString());
                        txtStockInCode.Text = string.Format("{0}", dt.Rows[0]["StockInCode"].ToString());
                        break;
                    default:
                        break;
                }
                if (!txtSupplierCode.Text.Equals(""))
                {
                    m_strSupplierCode = txtSupplierCode.Text.Split('|')[1];
                    m_strSupplierName = txtSupplierCode.Text.Split('|')[0];
                    m_strStockInCode = txtStockInCode.Text;
                    DialogResult = DialogResult.OK;
                }
            }
            catch
            {
            }
        }        
        #endregion        

        #region 03.系统事件方法

        private void txtCode_KeyDown(object sender, KeyEventArgs e)
        {
            // 确定配送企业
            if (e.KeyCode == Keys.Return)
            {
                btnSave_Click(null,null);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            // 取配送企业
            txtCode.Text = txtCode.Text.Trim().Replace("，", ",");// 中文','处理
            string strCode = txtCode.Text.Trim();
            // 扫描发票
            if (strCode.Split(',').Length == 8)
            {
                strCode = strCode.Split(',')[2] + "," + strCode.Split(',')[3];
            }
            if (strCode.Length < 5)
            {
                CommFun._messageBoxShow("编码位数太短,请确认！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                _getSupplier(strCode);
            }
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}